/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bounceboxapp;

import bouncebox.BounceBox;
import bouncebox.Circle;
import bouncebox.Square;
import bounceboxframework.Shape;
import java.awt.Color;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author p0073862
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException {
        BounceBox box = new BounceBox(700, 500);
        FileInputStream fileIn = new FileInputStream("practical8.txt");
        Scanner scan = new Scanner(fileIn);

        int squareNumber = 0, circleNumber = 0;
        double totalArea = 0.0;

        while (scan.hasNext()) {
            Shape shape;
            String shapeName = scan.next();
            int x = scan.nextInt();
            int y = scan.nextInt();
            int dimension = scan.nextInt();

            int vx = 0, vy = 0, red = 0, green = 0, blue = 0;
            if (scan.hasNextInt()) {
                vx = scan.nextInt();
                vy = scan.nextInt();
            }
            if (scan.hasNextInt()) {
                red = scan.nextInt();
                green = scan.nextInt();
                blue = scan.nextInt();
            }

            if (shapeName.equals("Circle")) {
                shape = new Circle(x, y, dimension);
                if (vx != 0 && vy != 0) {
                    shape.setVelocity(vx, vy);
                    if (red >= 0 && red <= 255 && green >= 0 && green <= 255 && blue >= 0 && blue <= 255) {
                        Color color = new Color(red, green, blue);
                        shape.setColor(color);
                    }
                }
                circleNumber++;
                totalArea += Math.PI * Math.pow(dimension, 2);
                box.addShape(shape);
            } else if (shapeName.equals("Square")) {
                shape = new Square(x, y, dimension);
                if (vx != 0 && vy != 0) {
                    shape.setVelocity(vx, vy);
                    if (red >= 0 && red <= 255 && green >= 0 && blue >= 0 && blue <= 255) {
                        Color color = new Color(red, green, blue);
                        shape.setColor(color);
                    }
                }
                squareNumber++;
                totalArea += Math.pow(dimension, 2);
                box.addShape(shape);
            } else {
                System.err.println("Ignore unkown shape:" + shapeName);
            }
        }

        System.out.println("squareNumber:" + squareNumber + " circleNumber:" + circleNumber + "\n totalArea:" + totalArea);
        addShapes();
    }





    private static void addShapes() throws FileNotFoundException {

        BounceBox box = new BounceBox(700, 500);

        FileInputStream fileIn = new FileInputStream("practical8.txt");
        Scanner scan = new Scanner(fileIn);
        while (scan.hasNext()) {
            Shape shape; //You should import Shape
            String shapeName = scan.next(); //get the first token
            int x = scan.nextInt();
            int y = scan.nextInt();
            int dimension = scan.nextInt();

            int vx = 0, vy = 0, red = 0, green = 0, blue = 0;
            if (scan.hasNextInt()) { // Set the velocity if it has
                vx = scan.nextInt();
                vy = scan.nextInt();
            }
            if (scan.hasNextInt()) { // Set the color if it has
                red = scan.nextInt();
                green = scan.nextInt();
                blue = scan.nextInt();
            }
            if (shapeName.equals("Circle")) {
                shape = new Circle(x, y, dimension); //Create the instance of Circle
                if (vx != 0 && vy != 0) { // check if velocity has been specified
                    shape.setVelocity(vx, vy);
                    if (red >= 0 && red <= 255 && green >= 0 && green <= 255 && blue >= 0 && blue <= 255) {
                        // check if color has been specified and is valid
                        Color color = new Color(red, green, blue);
                        shape.setColor(color);
                    }
                }
                box.addShape(shape);
            } else if (shapeName.equals("Square")) {
                shape = new Square(x, y, dimension); //Create the instance of Square
                if (vx != 0 && vy != 0) { // check if velocity has been specified
                    shape.setVelocity(vx, vy);
                    if (red >= 0 && red <= 255 && green >= 0 && green <= 255 && blue >= 0 && blue <= 255) {
                        // check if color has been specified and is valid
                        Color color = new Color(red, green, blue);
                        shape.setColor(color);
                    }
                }
                box.addShape(shape);
            }

        }
        // Start bouncing
        box.start();
    }
}